import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      })
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
      // 这里的 @ 就是我们要为 src 配置的别名
    }
  },
  // 反向代理
  server: {
    host: '0.0.0.0', //服务器ip地址
    port: 8041, //本地端口
    fs: {
      strict: false //  支持引用除入口目录的文件
    },
    open: true, // 是否自动在浏览器打开
    proxy: {
      '/api': {
        target: 'https://www.51jhwx.com/api/',//最新线上地址
        // target: 'http://192.168.1.25:8080/', //LW本地
				// target: 'http://118.31.185.32:7903/api/',//线上测试

        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    }
  },
  build: {
    //打包环境移除console.log，debugger
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    }
    //打包文件按照类型分文件夹显示
    // rollupOptions: {
    //   input: {
    //     main: path.resolve(__dirname, '/index.html')
    //   },
    //   output: {
    //     chunkFileNames: 'js/[name]-[hash].js',
    //     entryFileNames: 'js/[name]-[hash].js',
    //     assetFileNames: '[ext]/[name]-[hash].[ext]'
    //   }
    // }
  }
})
